package hczc.longcai.com.hccrowdfunding.home.fourth_mine.activities;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.activity.BaseActivity;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;
import hczc.longcai.com.hccrowdfunding.home.fourth_mine.adapters.AddIncomeAdapter;
import hczc.longcai.com.hccrowdfunding.home.fourth_mine.beans.AddIncome;

public class AddIncomeActivity extends BaseActivity implements View.OnClickListener {


    private static final String TAG = "AddIncomeActivicy";
    private ListView listView;
    private List<AddIncome> list;
    private AddIncomeAdapter adapter;
    private TextView money;

    private String[] projects = {"西部计划", "西气东输", "十三五规划"};
    private String[] income = {"169.32元", "500.00元", "5000.50元"};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_income);

        initDatas();
        initViews();
    }

    private void initDatas() {
        list = new ArrayList<>();
        int length = projects.length;
        for (int i = 0; i < length; i++) {
            AddIncome income = new AddIncome(projects[i], this.income[i]);
            list.add(income);
        }

    }

    private float getMoney(String m) {
        float money = 0f;
        String[] s = m.split("元");
        for (String c : s) {
            money = Float.valueOf(c);
        }

        return money;
    }

    private float getIncome(){
        float income = 0f;
        int length = this.income.length;
        for(int i = 0; i < length; i++){
            income += getMoney(this.income[i]);
        }
//        Log.d(TAG,"累计收益："+String.valueOf(income));
        return income;
    }


    private void initViews() {
        findViewById(R.id.head_back).setOnClickListener(this);
        ((TextView) findViewById(R.id.head_title)).setText("累计收益");

        View view = LayoutInflater.from(this).inflate(R.layout.header_add_income, null);
        BaseApplication.scaleScreenHelper.loadView(((ViewGroup) view));

        money = ((TextView) findViewById(R.id.add_income_money));
        float income = getIncome();
        money.setText(String.valueOf(income));

        listView = ((ListView) findViewById(R.id.mine_add_income_listView));
        listView.addHeaderView(view, null, false);
        adapter = new AddIncomeAdapter(this, list);
        listView.setAdapter(adapter);

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.head_back:
                finish();
                break;
        }
    }
}
